import scrapy
from ..items import BookItem
class MyspiderSpider(scrapy.Spider):
    name = 'MySpider'
    allowed_domains = ['www.tup.tsinghua.edu.cn']
    start_urls = ['http://www.tup.tsinghua.edu.cn/booksCenter/booklist.html?keyword=C%E8%AF%AD%E8%A8%80&keytm=8E393C24928991608D']

    def parse(self, response):
        books=response.xpath('//*[@id="csproduct"]/li/a')
        # print(books)
        items=[]
        for book in books:
            item=BookItem()
            item["name"]=book.xpath('span/text()').extract()
            item["author"] = book.xpath('p[1]/text()').extract()
            item["isbn"] = book.xpath('p[2]/text()').extract()
            item["price"] = book.xpath('p[3]/text()').extract()
            item["image"] = book.xpath('img/@src').extract()
            items.append(item)
        return items


